package vn.sunnet.backviet01.game.coloa.util;

import org.anddev.andengine.entity.Entity;
import org.anddev.andengine.entity.IEntity;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.util.SmartList;

public class MyScene extends Scene {
	public int shadowIndex;

	public MyScene() {
		super();
	}

	public void attachChildToHighest(final IEntity pEntity) {
		super.attachChild(pEntity);
		if (this.mChildren != null)
			pEntity.setZIndex(mChildren.size());
		sortChildren();
	}

	public void attachChildZIndex(int index, final IEntity pEntity) {
		if (this.mChildren != null) {
			pEntity.setZIndex(mChildren.size());
			Entity child;
			int length = this.mChildren.size();
			for (int i = 0; i < length; i++) {
		      child = (Entity)this.mChildren.get(i);
		      if (!child.equals(pEntity) && child.getZIndex() >= index) {
		    	  child.setZIndex(child.getZIndex() + 1);
		      }
		    }
		}
		sortChildren();
		super.attachChild(pEntity);
	}

	public void onManagedUpdate(final float pSecondsElapsed) {
		sortChildren();
		super.onManagedUpdate(pSecondsElapsed);
	}
	
	public SmartList<IEntity> getChildList() {
		return mChildren;
	}
}
